package com.huilian.iotbox.admin.controller;

import com.huilian.iotbox.admin.service.OrderRefundService;
import com.huilian.iotbox.admin.service.UserService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.controller.BaseController;
import com.huilian.iotbox.data.dto.OrderRefundDto;
import com.huilian.iotbox.data.vo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 谢洛涛
 * @date 2021/7/28 11:45
 */
@RestController
@RequestMapping("/api/orderRefund")
public class OrderRefundController extends BaseController {
    @Autowired
    private OrderRefundService orderRefundService;
    @Autowired
    private UserService userService;

    @PostMapping("/refund")
    public ServerResponse refund(@RequestBody OrderRefundDto orderRefundDto, HttpServletRequest request){
        UserInfo userInfo = userService.getLoginUserInfo(request);
//        orderRefundDto.setUserInfo(userInfo);
        orderRefundDto.setOperatePassword(orderRefundDto.getOperatePassword().trim());
        orderRefundDto.setRefundReason(orderRefundDto.getRefundReason().trim());
        return orderRefundService.refund(orderRefundDto,userInfo);
    }
}
